<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// 检测当前网络状态
			this.checkNetworkStatus();

			// 监听网络状态变化
			wx.onNetworkStatusChange((res) => {
				console.log('网络状态变化：', res.isConnected, res.networkType);
				if (!res.isConnected) {
					this.toErrIndex()
				}
			});
		},

		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			toErrIndex() {
				uni.redirectTo({
					url: "/pages/NotNetwork/NotNetwork"
				});
			},
			checkNetworkStatus() {
				wx.getNetworkType({
					success: (res) => {
						console.log('当前网络状态：', res.networkType);
						if (res.networkType === 'none') {
							this.toErrIndex()
						}
					},
					fail: (err) => {
						console.error('获取网络状态失败：', err);
						this.toErrIndex()
					}
				});
			},
		},
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "uview-plus/theme.scss";
</style>